/**
 * Created on 2007-03-09 21:38
 */
package tools;

import java.util.Random;

/**
 * @author David Wallin
 */
public class Randomizer
{
	/**
	 * The one instance of this class
	 */
	public static final Randomizer		INSTANCE = new Randomizer();
	
	/**
	 * The Random object to generate numbers with
	 */
	private Random						m_Random;
	
	/**
	 * Gets the next random number between min (inclusive) and max (inclusive)
	 * 
	 * @param min the smallest number to get from the random generator
	 * @param max the biggest number to get from the random generator
	 * @return a random number from min to max
	 */
	public int getNextInt(int min, int max)
	{
		float randomFloat = m_Random.nextFloat();
		int randomInt = (int)((randomFloat * (float)(max - min)) + 0.5f) + min;
		
		if(randomInt < min)
		{
			System.out.println("randomizer produced " + randomInt + " from parameters (" + min + ", " + max + ")");
			randomInt = min;
		}
		
		if(randomInt > max)
		{
			System.out.println("randomizer produced " + randomInt + " from parameters (" + min + ", " + max + ")");
			randomInt = max;
		}
		
		return randomInt;
	}
	
	/**
	 * Constructor, initializes members
	 */
	private Randomizer()
	{
		m_Random = new Random();
		m_Random.setSeed(System.currentTimeMillis());
	}
}
